public class Myqueue {
    static class ListNode{
        int val;
        public ListNode next;
        public ListNode pre;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode head;
    public ListNode last;
    public boolean offer(int val){
        ListNode node = new ListNode(val);
        if(head==null){
            head = node;
            last = node;
        }
        else{
            last.next = node;
            node.pre = last;
            last = last.next;
        }
        return true;
    }
    public int poll(){
        if(head==null){
            return -1;
        }
       if(head.next==null){
           int  retval = head.val;
           head = null;
           last = null;
           return retval;
       }else{
           int retval = head.val;
           head = head.next;
           head.pre = null;
           return retval;
       }
    }
    public int peek(){
        if(head==null){
            return -1;
        }
        return head.val;
    }
    public boolean empty(){
        return head==null;
    }

}
